package com.ymatou.iapi.dglogin.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.common.lang.CipherUtil;
import com.ymatou.iapi.dglogin.parameter.Wxh5loginBean;
import com.ymatou.iapi.dglogin.service.Wxh5loginCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.DGThirdPartyBindInfo;
import com.ymttest.database.model.DGUserExtInfo;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.model.DGWxUnionidBindInfo;
import com.ymttest.database.model.godmember.Member;
import com.ymttest.utils.TestDataManager;
import com.ymttest.database.sqlwapper.DGUserWapper;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;

/**
 * 买家微信H5登录 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_Wxh5login {
	private static Wxh5loginBean wxh5loginBean;
	private static Wxh5loginCall wxh5loginCall;
	private static String MCOKURL = "http://headimgurl.com";
	private static Integer UserGender = 1;
	DGUserWapper DGUserWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("买家微信H5登录");
	}

	@Before
	public void caseUp() {
		wxh5loginBean = new Wxh5loginBean();
		wxh5loginCall = new Wxh5loginCall();
		DGUserWapper = new DGUserWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(wxh5loginCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verifyDB(UserCreateBean usercreateBean2, Integer uid) {
		Logger.comment("验证DGUserInfo");
		DGUserInfo uinfo = DGUserWapper.selectDGUserInfo(uid).get(0);
		Logger.verifyEquals(usercreateBean2.getIscs() == null ? false : usercreateBean2.getIscs(), uinfo.getIsCs(), "验证IsCs");
		// loginid随机生成
		Logger.verifyNotNull(uinfo.getLoginId(), "验证LoginId");
		Logger.verifyNotNull(uinfo.getLoginPwd(), "验证LoginPwd");
		Logger.verifyEquals(usercreateBean2.getLogoUrl(), uinfo.getLogoUrl(), "验证LogoUrl");
		if (usercreateBean2.getMobile() != null) {
			Logger.verifyEquals(usercreateBean2.getMobile(), uinfo.getMobile(), "验证Mobile");
		}
		if (usercreateBean2.getMobileAreaCode() != null) {
			Logger.verifyEquals(usercreateBean2.getMobileAreaCode(), uinfo.getMobileAreaCode(), "验证MobileAreaCode");
		}
		if (usercreateBean2.getBelongSellerId() != null) {
			Logger.verifyEquals(usercreateBean2.getBelongSellerId(), uinfo.getBelongSellerId(), "验证BelongSellerId");
		}
		if(usercreateBean2.getNickname()!=null&&usercreateBean2.getNickname().length()>0) {
			Logger.verifyEquals(usercreateBean2.getNickname(), uinfo.getNickname(), "验证Nickname");
		}
		Logger.verifyEquals(usercreateBean2.getUserGender() == null ? 0 : usercreateBean2.getUserGender(), uinfo.getUserGender(), "验证UserGender");
		Logger.verifyEquals(usercreateBean2.getUserType() == null ? 0 : usercreateBean2.getUserType(), uinfo.getUserType(), "验证UserType");
		Logger.verifyEquals(0, uinfo.getUserStatus(), "验证UserStatus");
		Logger.comment("验证DGUserExtInfo");
		DGUserExtInfo exinfo = DGUserWapper.selectDGUserExtInfo(uid).get(0);
		Logger.verifyEquals(usercreateBean2.getAppSource(), exinfo.getAppSource(), "验证AppSource");
		Logger.verifyEquals(usercreateBean2.getChannelSource() == null ? 0 : usercreateBean2.getChannelSource(), exinfo.getChannelSource(), "验证ChannelSource");
		if (usercreateBean2.getClientIp() != null) {
			Logger.verifyEquals(usercreateBean2.getClientIp(), exinfo.getClientIp(), "验证ClientIp");
		}
		if (usercreateBean2.getCountryCode() != null) {
			Logger.verifyEquals(usercreateBean2.getCountryCode(), exinfo.getCountryCode(), "验证CountryCode");
		}
		// 根据uid和oid生成设备号
		Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getUnionId()), exinfo.getPhysicsDeviceId(), "验证DeviceId");
		Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getOpenId()), exinfo.getLogicDeviceId(), "验证EquipmentId");
		if (usercreateBean2.getInvitationCode() != null) {
			Logger.verifyEquals(usercreateBean2.getInvitationCode(), exinfo.getInvitationCode(), "验证InvitationCode");
		}
		// 现在没有remark
		// if (usercreateBean2.getRemark() != null) {
		// Logger.verifyEquals(usercreateBean2.getRemark(), exinfo.getRemark(),
		// "验证Remark");
		// }
		Logger.verifyEquals(usercreateBean2.getTerminalSource() == null ? 0 : usercreateBean2.getTerminalSource(), exinfo.getTerminalSource(), "验证TerminalSource");
		Logger.comment("验证DGThirdPartyBindInfo");
		DGThirdPartyBindInfo tpinfo = DGUserWapper.selectDGThirdPartyBindInfo(uid).get(0);
		// 多绑定关系在login站点考虑 这里主要看数据落地正确
		Logger.verifyEquals(usercreateBean2.getAppSource(), tpinfo.getAppSource(), "验证AppSource");
		Logger.verifyEquals(usercreateBean2.getOpenId(), tpinfo.getOpenId(), "验证OpenId");
		Logger.verifyEquals(usercreateBean2.getChannelSource() == null ? 0 : usercreateBean2.getChannelSource(), tpinfo.getThirdPartyType(), "验证ThirdPartyType");
		if (usercreateBean2.getUnionId() != null) {
			Logger.verifyEquals(usercreateBean2.getUnionId(), tpinfo.getUnionId(), "验证UnionId");
		}
		Logger.verifyEquals(usercreateBean2.getUserType() == null ? 0 : usercreateBean2.getUserType(), tpinfo.getUserType(), "验证UserType");

		Logger.comment("验证DGWxUnionidBindInfo");
		List<DGWxUnionidBindInfo> wxuinfo = DGUserWapper.selectDGWxUnionidBindInfo(uid);
		if (wxuinfo.size() > 0) {
			Logger.verifyEquals(usercreateBean2.getUserType() == null ? 0 : usercreateBean2.getUserType(), wxuinfo.get(0).getUserType(), "验证UserType");
			Logger.verifyEquals(usercreateBean2.getUnionId(), wxuinfo.get(0).getUnionId(), "验证UnionId");
		}
	}

	/**
	 * @param wxh5loginBean2
	 * @param oid
	 * @param uid
	 * @param name
	 * @return
	 */
	private UserCreateBean initUserCreateBean(Wxh5loginBean wxh5loginBean2, String oid, String uid, String name) {
		UserCreateBean usercreateBean2 = new UserCreateBean();
		usercreateBean2.setAppSource(wxh5loginBean.getAppSource());
		usercreateBean2.setClientIp(wxh5loginBean.getClientIp());
		usercreateBean2.setNickname(name);
		usercreateBean2.setOpenId(oid);
		usercreateBean2.setUnionId(uid);
		usercreateBean2.setWxAppName(wxh5loginBean.getWxAppName());
		usercreateBean2.setChannelSource(6);
		usercreateBean2.setLogoUrl(MCOKURL);
		usercreateBean2.setUserGender(UserGender);
		return usercreateBean2;
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Wxh5login_001() {
		Logger.start(true, "买家微信H5登录-新用户注册成功");
		try {
			String oid = "oid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000;
			String uid = "uid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000;
			String name = "nick1";
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", oid);

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", oid);
			wxh5loginCall.addHeader("mockParam-2-unionId", uid);
			wxh5loginCall.addHeader("mockParam-2-nickname", name);
			wxh5loginCall.getReqHeader().forEach(x->{
				Logger.debug(x);
			});
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("true", wxh5loginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxh5loginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(wxh5loginCall.getString("accessToken"), "验证accessToken");
			Integer userId = Integer.valueOf(wxh5loginCall.getString("userId"));
			// 参数来自wxh5loginBean 和mock默认
			UserCreateBean usercreateBean2 = initUserCreateBean(wxh5loginBean, oid, uid, name);
			verifyDB(usercreateBean2, userId);
			Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getUnionId()),  wxh5loginCall.getString("deviceId"), "验证DeviceId");
			Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getOpenId()),  wxh5loginCall.getString("cookieId"), "验证EquipmentId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_Wxh5login_002() {
		Logger.start(true, "买家微信H5登录-openid存在成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			// String oid="oid" + TestDataManager.getRandomNum(5) +
			// System.currentTimeMillis() % 1000;
			// String uid="uid" + TestDataManager.getRandomNum(5) +
			// System.currentTimeMillis() % 1000;
			// String name="nick1";
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", u.getOpenId());

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", u.getOpenId());
			wxh5loginCall.addHeader("mockParam-2-unionId", u.getUnionId() + 1);
			wxh5loginCall.addHeader("mockParam-2-nickname", u.getNickname());
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("true", wxh5loginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxh5loginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(wxh5loginCall.getString("accessToken"), "验证accessToken");
			Integer userId = Integer.valueOf(wxh5loginCall.getString("userId"));
			Logger.verifyEquals(userid, userId, "验证userid一致");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_Wxh5login_003() {
		Logger.start(true, "买家微信H5登录-unionid存在成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			// String oid="oid" + TestDataManager.getRandomNum(5) +
			// System.currentTimeMillis() % 1000;
			// String uid="uid" + TestDataManager.getRandomNum(5) +
			// System.currentTimeMillis() % 1000;
			// String name="nick1";
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", u.getOpenId() + 1);

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", u.getOpenId() + 1);
			wxh5loginCall.addHeader("mockParam-2-unionId", u.getUnionId());
			wxh5loginCall.addHeader("mockParam-2-nickname", u.getNickname());
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("true", wxh5loginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxh5loginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(wxh5loginCall.getString("accessToken"), "验证accessToken");
			Integer userId = Integer.valueOf(wxh5loginCall.getString("userId"));
			Logger.verifyEquals(userid, userId, "验证userid一致");

			Logger.comment("验证DGThirdPartyBindInfo");
			// 多绑定关系 先查原始注册数据
			DGThirdPartyBindInfo tpinfo = DGUserWapper.selectDGThirdPartyBindInfo(userId).stream().filter(dgu -> dgu.getOpenId().equals(u.getOpenId())).findFirst().get();
			Logger.verifyEquals(u.getAppSource(), tpinfo.getAppSource(), "验证AppSource");
			Logger.verifyEquals(u.getOpenId(), tpinfo.getOpenId(), "验证OpenId");
			Logger.verifyEquals(u.getChannelSource() == null ? 0 : u.getChannelSource(), tpinfo.getThirdPartyType(), "验证ThirdPartyType");
			if (u.getUnionId() != null) {
				Logger.verifyEquals(u.getUnionId(), tpinfo.getUnionId(), "验证UnionId");
			}
			Logger.verifyEquals(u.getUserType() == null ? 0 : u.getUserType(), tpinfo.getUserType(), "验证UserType");
			// 多绑定关系 查询wxh5login 联登进来的数据
			tpinfo = DGUserWapper.selectDGThirdPartyBindInfo(userId).stream().filter(dgu -> dgu.getOpenId().equals(u.getOpenId()+1)).findFirst().get();
			Logger.verifyEquals(wxh5loginBean.getAppSource(), tpinfo.getAppSource(), "验证AppSource");
			Logger.verifyEquals(u.getOpenId()+1, tpinfo.getOpenId(), "验证OpenId");
			Logger.verifyEquals(u.getChannelSource() == null ? 0 : u.getChannelSource(), tpinfo.getThirdPartyType(), "验证ThirdPartyType");
			if (u.getUnionId() != null) {
				Logger.verifyEquals(u.getUnionId(), tpinfo.getUnionId(), "验证UnionId");
			}
			Logger.verifyEquals(u.getUserType() == null ? 0 : u.getUserType(), tpinfo.getUserType(), "验证UserType");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_Wxh5login_004() {
		Logger.start(true, "不输入wxAppName失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
//			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", u.getOpenId() );

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", u.getOpenId());
			wxh5loginCall.addHeader("mockParam-2-unionId", u.getUnionId());
			wxh5loginCall.addHeader("mockParam-2-nickname", u.getNickname());
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("false", wxh5loginCall.getString("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_Wxh5login_005() {
		Logger.start(true, "不输入code失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
//			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", u.getOpenId() );

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", u.getOpenId());
			wxh5loginCall.addHeader("mockParam-2-unionId", u.getUnionId());
			wxh5loginCall.addHeader("mockParam-2-nickname", u.getNickname());
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("false", wxh5loginCall.getString("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_Wxh5login_006() {
		Logger.start(true, "不输入clientIp成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
//			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", u.getOpenId() );

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", u.getOpenId());
			wxh5loginCall.addHeader("mockParam-2-unionId", u.getUnionId());
			wxh5loginCall.addHeader("mockParam-2-nickname", u.getNickname());
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("true", wxh5loginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxh5loginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(wxh5loginCall.getString("accessToken"), "验证accessToken");
			Integer userId = Integer.valueOf(wxh5loginCall.getString("userId"));
			Logger.verifyEquals(userid, userId, "验证userid一致");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_Wxh5login_007() {
		Logger.start(true, "不输入appsource失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
//			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", u.getOpenId() );

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", u.getOpenId());
			wxh5loginCall.addHeader("mockParam-2-unionId", u.getUnionId());
			wxh5loginCall.addHeader("mockParam-2-nickname", u.getNickname());
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("false", wxh5loginCall.getString("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_Wxh5login_008() {
		Logger.start(true, "输入WxAppName不匹配失败");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer userid = DGUserCallService.UserCreateCall(u);
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_SellerApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqSeller);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", u.getOpenId() );

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", u.getOpenId());
			wxh5loginCall.addHeader("mockParam-2-unionId", u.getUnionId());
			wxh5loginCall.addHeader("mockParam-2-nickname", u.getNickname());
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("false", wxh5loginCall.getString("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Wxh5login_009() {
		Logger.start(true, "买家微信H5登录-新用户注册成功-emoji表情nickname");
		try {
			String oid = "oid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000;
			String uid = "uid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000;
			//mock 模板写死数据 emoji表情放在httpheader上服务端无法接受
			String name = "nick1:;;;;😑😊😳";
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", oid);

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-emoji");
			wxh5loginCall.addHeader("mockParam-2-openId", oid);
			wxh5loginCall.addHeader("mockParam-2-unionId", uid);
//			wxh5loginCall.addHeader("mockParam-2-nickname", name);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("true", wxh5loginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxh5loginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(wxh5loginCall.getString("accessToken"), "验证accessToken");
			Integer userId = Integer.valueOf(wxh5loginCall.getString("userId"));
			// 参数来自wxh5loginBean 和mock默认
			UserCreateBean usercreateBean2 = initUserCreateBean(wxh5loginBean, oid, uid, name);
			verifyDB(usercreateBean2, userId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Wxh5login_010() {
		Logger.start(true, "买家微信H5登录-新用户注册成功-传入参数mchId会去注册会员");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			String oid = "oid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000;
			String uid = "uid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000;
			String name = "nick1";
			wxh5loginBean.setMchId(mchId);
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", oid);

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", oid);
			wxh5loginCall.addHeader("mockParam-2-unionId", uid);
			wxh5loginCall.addHeader("mockParam-2-nickname", name);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("true", wxh5loginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxh5loginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(wxh5loginCall.getString("accessToken"), "验证accessToken");
			Integer userId = Integer.valueOf(wxh5loginCall.getString("userId"));
			// 参数来自wxh5loginBean 和mock默认
			UserCreateBean usercreateBean2 = initUserCreateBean(wxh5loginBean, oid, uid, name);
			verifyDB(usercreateBean2, userId);
			Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getUnionId()),  wxh5loginCall.getString("deviceId"), "验证DeviceId");
			Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getOpenId()),  wxh5loginCall.getString("cookieId"), "验证EquipmentId");
			
			Thread.sleep(3000);
			 List<Member> mems = new GodMemberWapper().selectMemberByUserId(userId, mchId);
			 Logger.verifyEquals(1, mems.size(), "验证创建会员");
			Logger.debug("userId:"+userId+":mchId:"+mchId+":"+FormatUtil.beanToGSONString(mems));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_Wxh5login_011() {
		Logger.start(true, "买家微信H5登录-新用户注册成功-nickname为空");
		try {
			String oid = "oid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000;
			String uid = "uid" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000;
			String name = "";
			wxh5loginBean.setClientIp(TestDataManager.getRandomIp());
			wxh5loginBean.setCode("abcdefg");
			wxh5loginBean.setAppSource(DGUserCallService.DG_BuyerWxApp);
			wxh5loginBean.setWxAppName(DGUserCallService.TestWxsqBuyer);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.addHeader("mock", "mock-enable");
			wxh5loginCall.addHeader("mockId-1", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-1", "dgLoginWxClient-getAccessToken-Normal");
			String token = ("token" + TestDataManager.getRandomNum(5) + System.currentTimeMillis() % 1000);
			wxh5loginCall.addHeader("mockParam-1-token", token);
			wxh5loginCall.addHeader("mockParam-1-openId", oid);

			wxh5loginCall.addHeader("mockId-2", TestDataManager.getRandomUUID().toString());
			wxh5loginCall.addHeader("mockApi-2", "dgLoginWxClient-getUserInfo-Normal");
			wxh5loginCall.addHeader("mockParam-2-openId", oid);
			wxh5loginCall.addHeader("mockParam-2-unionId", uid);
			wxh5loginCall.addHeader("mockParam-2-nickname", name);
			wxh5loginCall.setData(wxh5loginBean);
			wxh5loginCall.callService();
			Logger.verifyEquals("true", wxh5loginCall.getString("success"), "验证success");
			Logger.verifyNotNull(wxh5loginCall.getString("userId"), "验证userId");
			Logger.verifyNotNull(wxh5loginCall.getString("accessToken"), "验证accessToken");
			Integer userId = Integer.valueOf(wxh5loginCall.getString("userId"));
			// 参数来自wxh5loginBean 和mock默认
			UserCreateBean usercreateBean2 = initUserCreateBean(wxh5loginBean, oid, uid, name);
			verifyDB(usercreateBean2, userId);
			Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getUnionId()),  wxh5loginCall.getString("deviceId"), "验证DeviceId");
			Logger.verifyEquals(CipherUtil.encryptMD5(usercreateBean2.getOpenId()),  wxh5loginCall.getString("cookieId"), "验证EquipmentId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}